<?php
	include("bp-location.php");
?>
<html>
<head>
	<title>GradeGrid - Customize Account</title>
	<?php
		include("header.php");
		include("write_functions.php");
	?>
	
	<?php
		connect("localhost", "root", "", "gradegriddatabase");
		$loginid = mysql_real_escape_string($_POST["username"]);
		$password = mysql_real_escape_string(sha1($_POST["password"]));
		$email = mysql_real_escape_string($_POST["email"]);
		
		$existencecheck_query= mysql_query("SELECT username FROM account WHERE username = '$loginid'");
		$doesExist = mysql_num_rows($existencecheck_query) > 0;
		
		if($doesExist){
			//Do something and notify the user.
		} else{
			//$accounts_database = mysql_connect("localhost", "root", "");
			
			
			//mysql_select_db("gradegriddatabase", $accounts_database);
			
			$debug = mysql_query("INSERT INTO account(username, password, email, type) VALUES ('$loginid', '$password', '$email', 'I')");
		
			if(!$debug){
				throw new Exception("Error inserting record: " . mysql_error());
			}
			
		}
		
		//mysql_close($accounts_database);
	?>
	<script type="text/javascript" language="javascript">
		function skip(){
			window.location.replace("/gradegrid/useraccount/settings.php?page=class")
		}
		
		function validate(){
			var contactno = document.getElementById("contactno")
			var numericregex = /\d+/
			
			try{
				if(numericregex.test(contactno.value)){
					submit()
				} else{
					alert("Contact number must be in numeric form.")
					contactno.select()
				}
			} catch(e){
			}
			
			document.getElementById("customize").submit()
		}
	</script>
</head>
<body onLoad="writeCopyright()">
	<div class="main">
	<?php include("boilerplate.php"); ?>
		
	<span id="login_error_message"></span>
	<form action="useraccount/settings.php?page=class" id="customize" method="post">
	<div class="form_section" style="width: 90%;"><h1>Further Customization</h1></div>
	<table style="border: none;" class="pMirror">
		<tr>
			<td class="indentRight">First Name:</td>
			<td><input type="text" name="first_name" /></td>
		</tr>
		<tr>
			<td class="indentRight">Middle Name:</td>
			<td><input type="text" name="middle_name" /></td>
		</tr>
		<tr>
			<td class="indentRight">Last Name:</td>
			<td><input type="text" name="last_name" /></td>
		</tr>
		<tr><!--Maybe this should be moved to signup.php (?)-->
			<td class="indentRight">Sex:</td>
			<td>
			<input type="radio" name="sex" value="M" checked="checked"> M<br />
			<input type="radio" name="sex" value="F"> F
			</td>
		<tr><!--TODO: Fix this!-->
			<td class="indentRight">Birthday:</td>
			<td>
				<select id="years">
				</select>
				
				<select id="months" onchange="showDates()">
				</select>
				
				<select id="dates">
				</select>
				
				<script type="text/javascript" language="javascript" src="boilerplate/js/birthday.js"></script>
			</td>
		</tr>
		<tr>
			<td>Contact Number:</td>
			<td><input type="text" name="contactno" id="contact_number" /></td>
		</tr>
		<tr>
			<td>Country:</td>
			<td><input type="text" name="country" /></td>
		</tr>
		<tr>
			<td>City/Province:</td>
			<td><input type="text" name="city_province" /></td>
		</tr>
		<tr>
			<td>Municipality:</td>
			<td><input type="text" name="municipality" /></td>
		</tr>
		<tr>
			<td>Street:</td>
			<td><input type="text" name="street" /></td>
		</tr>
	</table>
	<br />
	<input type="button" onclick="skip()" value="Skip" /> <input type="button" onclick="validate()" value = "Save" />
	</div>
	</form>
	<div id="copywright"></div>
</body>
</html>